package org.example.supplychain.mapper;

import org.apache.ibatis.annotations.*;
import org.example.supplychain.domain.TotalMaterial;

import java.util.List;

@Mapper
public interface TotalMaterialMapper {

    /**
     * 添加总物料
     *
     * @param totalMaterial 总物料
     */
    @Insert("INSERT INTO total_material(material_name,material_total_number,minimum_stock,warning_state) VALUES (#{materialName},#{materialTotalNumber},#{minimumStock},#{warningState})")
    void addTotalMaterial(TotalMaterial totalMaterial);

    /**
     * 删除总物料
     *
     * @param materialName 物料名称
     */
    @Delete("DELETE FROM total_material WHERE material_name = #{materialName}")
    void deleteTotalMaterialByMaterialName(String materialName);

    /**
     * 更新总物料
     *
     * @param totalMaterial 总物料
     */
    @Update("UPDATE total_material SET material_total_number = #{materialTotalNumber},minimum_stock = #{minimumStock},warning_state = #{warningState} WHERE material_name = #{materialName}")
    void updateTotalMaterialByMaterialName(TotalMaterial totalMaterial);

    /**
     * 更新总物料物料总数
     *
     * @param totalMaterial 总物料
     */
    @Update("UPDATE total_material SET material_total_number = #{materialTotalNumber} WHERE material_name = #{materialName}")
    void updateMaterialTotalNumberByMaterialName(TotalMaterial totalMaterial);

    /**
     * 更新总物料最小库存
     *
     * @param totalMaterial 总物料
     */
    @Update("UPDATE total_material SET minimum_stock = #{minimumStock} WHERE material_name = #{materialName}")
    void updateMinimumStockByMaterialName(TotalMaterial totalMaterial);

    /**
     * 更新总物料预警状态
     *
     * @param totalMaterial 总物料
     */
    @Update("UPDATE total_material SET warning_state = #{warningState} WHERE material_name = #{materialName}")
    void updateWarningStateByMaterialName(TotalMaterial totalMaterial);

    /**
     * 根据物料名称获取总物料
     *
     * @param materialName 物料名称
     * @return 物料
     */
    @Select("SELECT * FROM total_material WHERE material_name = #{materialName}")
    TotalMaterial getTotalMaterialByMaterialName(String materialName);

    /**
     * 获取所有总量信息
     * @return 所有总量信息
     */
    @Select("SELECT * FROM total_material")
    List<TotalMaterial> getAllTotalMaterial();
}
